import http from "@/api/config";
var root = "/addons/up_vipcard/inc/web/public/index.php?s=";
// import { Message } from "element-ui";

const login = (callback) => {
  var url = root + "/Index/login";
  http.post(url).then((res) => {
    console.log("登录授权返回值：", res);
    callback(res.date);
  });
};

/**
 * 获取所有安装的应用
 * @param callback
 */
const myapp_getall = (callback) => {
  var url = root + "/MyApp/getAll";
  http.post(url).then((res) => {
    callback(res.date);
  });
};

/**
 * 获取某一个应用下面的二级列表
 * @param callback
 */
const myapp_menu_getall = (id, callback) => {
  var url = root + "/MyApp/getMenu";

  let data = new FormData();
  data.append("appid", id);

  http.post(url, data).then((res) => {
    callback(res.date);
  });
};

/**
 * 添加居间人信息
 * data参数说明
 * @param $name 仓库名称    必填
 * @param $card 仓库介绍
 */
const lntermediaries_save = (data, callback) => {
  var url = root + "/Lntermediaries/save";

  http.post(url, data).then((res) => {
    callback(res.date);
  });
};

/**
 * 根据ID获取居间人信息
 */
const lntermediaries_getInfoById = (id, callback) => {
  var url = root + "/Lntermediaries/getInfoById";

  let data = new FormData();
  data.append("id", id);

  http.post(url, data).then((res) => {
    callback(res.date);
  });
};

/**
 * 删除仓库
 * @param id 需要删除的唯一ID
 * @param callback
 */
const Lntermediaries_del = (id, callback) => {
  var url = root + "/Lntermediaries/del";
  let data = new FormData();
  data.append("id", id);

  http.post(url, data).then((res) => {
    callback(res.date);
    // Message.error("网络异常");
  });
};

export {
  login,
  myapp_getall,
  myapp_menu_getall,
  lntermediaries_save,
  lntermediaries_getInfoById,
  Lntermediaries_del,
};
